package edu.ucsd.ccdb.cytoSegPopup;

import javax.swing.JButton;

import org.jdesktop.swingworker.SwingWorker;

public class CytosegTask extends SwingWorker<Void, Void> {

	private JButton runButton;
	private String training1; 
	private String training2; 
	private String input;
	private String output;
	
	public CytosegTask( String training1, String training2, String input, String output, JButton runButton ) {
	
		this.training1 = training1;
		this.training2 = training2;
		this.input = input;
		this.output = output;
		this.runButton = runButton;
	}
	
	@Override
	protected Void doInBackground() throws Exception {

		// send the request and wait for response.
		
		String trimTraining1 = trim (training1);
		String trimTraining2 = trim (training2);
		String trimInput = trim (input);
		String trimOutput = trim (output );
		
		CytosegService.getExecutionSegtoseg( trimTraining1, trimTraining2, trimInput, trimOutput );
		
		return null;
	}
		
	protected void done () {
		runButton.setText("Done. Run again? (Will take eternity:D)");
		runButton.setEnabled(true);
	}
	
	private String trim (String data ) {
		
		if ( !data.endsWith("/") )  
			return data;
		
		return data.substring(0, data.length() - 1);
	}
	
	
}

